/*
 * Copyright the original author or authors.
 * 
 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *	  http://www.mozilla.org/MPL/MPL-1.1.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.milib.dbg.view.content.ease {
	import com.googlecode.milib.base.IMLBroadcasterListener;
	import com.googlecode.milib.base.MLBroadcastClass;
	import com.googlecode.milib.display.service.MLMC;
	import com.googlecode.milib.display.ui.slider.MCSlider;
	import com.googlecode.milib.vo.MLEventInfo;

	import flash.display.MovieClip;
	import flash.text.TextField;

	/**
	 * @author Marek Brun
	 */
	public class EasePropSlider extends MLBroadcastClass implements IMLBroadcasterListener {

		public const event_Changed : String = 'Changed';
		
		private var mlmc:MLMC;
		private var mc_sl : MovieClip;
		private var mc_tfTitle : TextField;
		private var slider:MCSlider;
		private var params:Array;

		public function EasePropSlider(mc:MovieClip) {
			mlmc=MLMC.forInstance(mc);
			mc_sl=MovieClip(mc.getChildByName('sl'));
			mc_tfTitle=TextField(mc.getChildByName('tfTitle'));
			slider=new MCSlider(mc_sl);
			slider.addListener(this);
		}
		
		override public function getPrivateVariables():Array {
			return [
				['slider', slider]
			].concat(super.getPrivateVariables());
		}
		
		public function getSlider():MCSlider {
			return slider;
		}
		
		public function get mc():MovieClip { return mlmc.mc; };
		
		public function setParams(params:Array):void {
			this.params=params;
			mc_tfTitle.text=params[0];
			//['humps', 1, 40, 5]
			slider.removeListener(this);
			slider.getModel().setMinMaxValue(params[1], params[2]);
			slider.addListener(this);
		}
		
//********************************************************************************************
//		events for EasePropSlider
//********************************************************************************************
		public function onEvent(ev:MLEventInfo):void {
			switch(ev.hero){
				case slider:
					switch(ev.event) {
						case slider.event_Changed:
							broadcastEvent(event_Changed);
						break;
					}
				break;
			}
		}
		
	}
}
